package 代码记录.校招笔试真题.笔试真题_2023.恒生电子;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

/**
 * 0%
 * 恒生电子是一家自己对自己没有逼数的公司
 */
public class Test2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        String str2 = sc.nextLine();
        List<Character> list1 = toList(str);
        int[] works = new int[list1.size()];
        for(int i = 0;i < works.length;i++){
            works[i] = list1.get(i) - '0';
        }
        List<Character> list2 = toList(str2);
        int workCount = list2.get(0) - '0';
        Arrays.sort(works);
        List<List<Integer>> res = new ArrayList<>();
        int[][] arr = new int[workCount][works.length / workCount + 1];
        int count = works.length - 1;
        while(count >= 0){
            for(int i = 0;i < arr[0].length;i++){
                int k = 0;
                while(k < arr.length){
                    if(k % 2 == 0){
                        for(int j = arr.length - 1;j >= 0;j--){
                            arr[i][j] = works[count];
                        }
                    }else{
                        for(int j = 0;j < arr.length - 1;j++){
                            arr[i][j] = works[count];
                        }
                    }
                    k++;
                }
            }
            count++;
        }
        int[] t = new int[workCount];
        for(int i = 0;i < arr.length;i++){
            int sum = 0;
            for(int j = 0;j < arr[0].length;j++){
                sum += arr[i][j];
            }
            t[i] = sum;
        }
        for(int i = 0;i < arr.length;i++){
            System.out.println(t[i] + ":" + Arrays.toString(arr[i]));
        }
    }

    /**
     * @return 输入格式处理
     */
    private static List<Character> toList(String str){
        List<Character> res = new ArrayList<>();
        for(int i = 0;i < str.length();i++){
            if(str.charAt(i) >= '0' && str.charAt(i) <= '9'){
                res.add(str.charAt(i));
            }
        }
        return res;
    }
}
